//
//  HealthToolController.m
//  HarmonizePub
//
//  Created by rzhy on 2016/11/2.
//  Copyright © 2016年 Zy. All rights reserved.
//

#import "HealthToolController.h"
#import "HealthToolTableCell.h"

static NSString *CellIdentifier = @"Cell";

@interface HealthToolController () <UITableViewDelegate, UITableViewDataSource>
{
    NSArray *_dataArray;
}
@property (weak, nonatomic) IBOutlet UITableView *tableView;

@end

@implementation HealthToolController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
//    self.title = @"健康工具";
    _dataArray = [NSArray arrayWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"HealthToolsData" ofType:@"plist"]];
    UINib *nib = [UINib nibWithNibName:[HealthToolTableCell registerName] bundle:nil];
    [self.tableView registerNib:nib forCellReuseIdentifier:CellIdentifier];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - tableView delegate/dataSource Method
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return _dataArray.count;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 55.0f;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    HealthToolTableCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    [cell setCellShowDataWithDataDictionary:_dataArray[indexPath.row]];
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [tableView deselectRowAtIndexPath:indexPath animated:NO];
    UIViewController *viewController = [[NSClassFromString(_dataArray[indexPath.row][@"class"]) alloc] init];
    [self.navigationController pushViewController:viewController animated:YES];
}


@end
